package com.enjoyor.soa.traffic.restt.tpcms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.IPassCardConsumeService;
import com.enjoyor.soa.traffic.restt.tpcms.dubbo.invoke.UbmsDeptBayonetServiceInvoke;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Auth
@RestController
@RequestMapping({ "/passCard" })
@Api("通行证管理Controller页面请求")
@CrossOrigin
public class PassCardController {

    @Autowired
    private IPassCardConsumeService passCardConsumeService;

    @Autowired
    private UbmsDeptBayonetServiceInvoke ubmsDeptService;
    /**
	 * 删除申请单
	 * @param passCardId 通行证编号
	 */
	@DeleteMapping(value = { "/deletePassCard" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除通行证")
    @ApiImplicitParam(name = "passCardId", value = "通行证编号", paramType = "query", required = true, dataType = "string")
    public ResultPojo deletePassApply(
    		@RequestParam(defaultValue = "") String passCardId, 
    		HttpServletRequest request) {
		return passCardConsumeService.deletePassCard(passCardId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	/**
	 * 通行证延期
	 * @param passCardId 通行证编号
	 * @param extensionPeople 延期申请人
	 * @param isSelf 是否本人
	 * @param extensionDays 延期天数
	 */
	@PutMapping(value = { "/extensionPassCard" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("通行证延期")
	@ApiImplicitParams({
    	@ApiImplicitParam(name = "passCardId", value = "通行证编号", paramType = "query", required = true, dataType = "string"),
        @ApiImplicitParam(name = "extensionPeople", value = "延期申请人", paramType = "query", required = true, dataType = "string"),
        @ApiImplicitParam(name = "isSelf", value = "是否本人（是1，否0）", paramType = "query", required = true, dataType = "string"),
        @ApiImplicitParam(name = "extensionDays", value = "延期天数", paramType = "query", required = true, dataType = "string")})
	public ResultPojo extensionPassCard(
			@RequestParam(defaultValue = "") String passCardId, 
			@RequestParam(defaultValue = "") String extensionPeople,
			@RequestParam(defaultValue = "") String isSelf, 
			@RequestParam(defaultValue = "") String extensionDays, 
			HttpServletRequest request) {
		return  passCardConsumeService.extensionPassCard(passCardId, extensionPeople, isSelf, 
                extensionDays, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 通行证打印
	 * @param passCardId 通行证编号
	 */
	@PutMapping(value = { "/printPassCard" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("通行证打印")
	@ApiImplicitParam(name = "passCardId", value = "通行证编号", paramType = "query", required = true, dataType = "string")
    public ResultPojo printPassCard(@RequestParam(defaultValue = "") String passCardId, HttpServletRequest request) {
		return passCardConsumeService.printPassCard(passCardId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	/**
	 * 查询通行证列表信息List
	 * @param passCardId 通行证编号
	 * @param passApplyId 申请编号
	 * @param effectStartTime 有效开始时间(yyyy-mm-dd)
	 * @param effectEndTime 有效结束时间(yyyy-mm-dd)
	 * @param passStatusId 通行证状态编号
	 * @return
	 */
    @GetMapping(value = { "/getPassCardList" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation(value = "获取通行证信息", notes = "查询数据库中符合条件的通行证数据")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "passCardId", value = "通行证编号", paramType = "query", dataType = "string"),
    	@ApiImplicitParam(name = "passApplyId", value = "申请编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "effectStartTime", value = "有效开始时间(yyyy-mm-dd)", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "effectEndTime", value = "有效结束时间(yyyy-mm-dd)", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "passStatusId", value = "通行证状态编号", paramType = "query", dataType = "string") })
	public ResultPojo getPassCardList(
			@RequestParam(defaultValue = "") String passCardId, 
			@RequestParam(defaultValue = "") String passApplyId, 
			@RequestParam(defaultValue = "") String effectStartTime,
			@RequestParam(defaultValue = "") String effectEndTime, 
			@RequestParam(defaultValue = "") String passStatusId, 
			HttpServletRequest request) {
        return passCardConsumeService.getPassCardList(passCardId, passApplyId, 
                effectStartTime, effectEndTime, passStatusId);
    }
    
    /**
	 * 查询申请单分页信息-审核模块
	 * @param page 分页参数
	 * @return
	 */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @GetMapping(value = { "/getPassCardPage" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation(value = "申请单分页查询", notes = "申请单分页查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "passCardId", value = "通行证编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "passApplyId", value = "申请编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "applyPeople", value = "申请人", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "applyDept", value = "所属单位（模糊查询）", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "licenseNumber", value = "车辆号牌", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "effectStartTime", value = "有效开始时间(yyyy-mm-dd)", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "effectEndTime", value = "有效结束时间(yyyy-mm-dd)", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "passStatusId", value = "通行证状态编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "dataDept", value = "数据权限部门", paramType = "query", dataType = "String") })
    public ResultPojo getPassCardPage(
    		@RequestParam(defaultValue = "") String passCardId, 
			@RequestParam(defaultValue = "") String passApplyId, 
			@RequestParam(defaultValue = "") String applyPeople,
			@RequestParam(defaultValue = "") String applyDept, 
			@RequestParam(defaultValue = "") String licenseNumber, 
			@RequestParam(defaultValue = "") String effectStartTime,
			@RequestParam(defaultValue = "") String effectEndTime, 
			@RequestParam(defaultValue = "") String passStatusId, 
			@RequestParam(defaultValue = "") String dataDept, 
    		Page page, HttpServletRequest request) {
    	Map<String,Object> mapBean = new HashMap<String,Object>();
    	mapBean.put("passCardId", passCardId);
    	mapBean.put("passApplyId", passApplyId);
    	mapBean.put("applyPeople", applyPeople);
    	mapBean.put("applyDept", applyDept);
    	mapBean.put("licenseNumber", licenseNumber);
    	mapBean.put("effectStartTime", effectStartTime);
    	mapBean.put("effectEndTime", effectEndTime);
    	mapBean.put("passStatusId", passStatusId);
    	if(null != dataDept && dataDept != "") {
    		List<String> dataDeptIds = ubmsDeptService.getDeptsByParentId(dataDept);
            mapBean.put("dataDeptIds", dataDeptIds);
    	}
    	page.setMapBean(mapBean);
        return passCardConsumeService.getPassCardPage(page);
    }
    
}
